package com.zprmb.udzt.adapter;

import java.text.DecimalFormat;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.RegularBean;
import com.zprmb.udzt.util.Regular;

public class Regular_Adapter1 extends BaseAdapter {
	private List<RegularBean> list;
	private Context context;
	DecimalFormat df = new DecimalFormat("###0.00");
	public Regular_Adapter1(List<RegularBean> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Help h=null;
		if(convertView==null){
			h=new Help();
			convertView=LayoutInflater.from(context).inflate(R.layout.regular_item, null);
			h.tv_name=(TextView)convertView.findViewById(R.id.conduct_name);
			h.tv_amount=(TextView)convertView.findViewById(R.id.amount);
			h.tv_period=(TextView)convertView.findViewById(R.id.product_period);
			h.tv_product_amount=(TextView)convertView.findViewById(R.id.product_amount);
			h.tv_rate=(TextView)convertView.findViewById(R.id.product_rate);
			h.tv_time=(TextView)convertView.findViewById(R.id.invest_time);
			h.tv_type=(TextView)convertView.findViewById(R.id.repayType);
			convertView.setTag(h);
		}else{
			h=(Help) convertView.getTag();
		}
		h.tv_name.setText(list.get(position).getProductName());
		h.tv_amount.setText(df.format(Double.parseDouble(list.get(position).getAmount())));
		
		h.tv_period.setText(list.get(position).getLoanPeriod());
		h.tv_product_amount.setText(df.format(Double.parseDouble(list.get(position).getProductAmount())));
		h.tv_rate.setText(df.format(Double.parseDouble(list.get(position).getRate()))+"%");
		h.tv_type.setText(list.get(position).getRepayType());
		h.tv_time.setText(Regular.getMilliToDate(list.get(position).getInvestTime()));
		return convertView;
	}
	class Help{
		private TextView tv_name,tv_product_amount,tv_rate,tv_period,tv_amount,tv_time,tv_type;
	}

}
